//
//  TimeFrameShowView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/21.
//

#import "TimeFrameShowView.h"

@interface TimeFrameShowView ()
@property (nonatomic ,strong) NSString * StartTime;
@property (nonatomic ,strong) NSString * EndTime;
@property (nonatomic ,strong) NSString * Title;
@property (nonatomic ,strong) UILabel * StartTimeLab;
@property (nonatomic ,strong) UIView * StartTimeview;
@property (nonatomic ,strong) UILabel * EndTimeLab;
@property (nonatomic ,strong) UIView * EndTimeview;


@property (nonatomic ,strong) void(^block)(NSString * StartTime,NSString * EndTime);
@property (nonatomic ,strong) void(^CZblock)(void);

@property (nonatomic ,strong) UIView * makeView;
@property (nonatomic ,assign) CGFloat viewH;
@property (nonatomic ,assign) BOOL isCZ;
@property (nonatomic ,strong) BRDatePickerView * pickerView;
@end

@implementation TimeFrameShowView
+ (instancetype)showviewWithTitle:(NSString *)Title andStartTime:(NSString *)StartTime andEndTime:(NSString *)EndTime andRightBlock:(void(^)(NSString * StartTime,NSString * EndTime))block  andCZBlock:(void(^)(void))CZBlock;{
    TimeFrameShowView * view = [TimeFrameShowView new];
    view.StartTime = StartTime;
    view.Title = Title;
    view.block = block;
    view.EndTime = EndTime;
    view.CZblock = CZBlock;
    [view setupview];
    return view;
}
+ (instancetype)CZshowviewWithTitle:(NSString *)Title andStartTime:(NSString *)StartTime andEndTime:(NSString *)EndTime andRightBlock:(void(^)(NSString * StartTime,NSString * EndTime))block andCZBlock:(void(^)(void))CZBlock{
    TimeFrameShowView * view = [TimeFrameShowView new];
    view.isCZ = YES;
    view.StartTime = StartTime;
    view.block = block;
    view.Title = Title;
    view.EndTime = EndTime;
    view.CZblock = CZBlock;
    [view setupview];
    return view;
}
+ (instancetype)showviewWithStartTime:(NSString *)StartTime andEndTime:(NSString *)EndTime andRightBlock:(void(^)(NSString * StartTime,NSString * EndTime))block  andCZBlock:(void(^)(void))CZBlock;{
    TimeFrameShowView * view = [TimeFrameShowView new];
    view.StartTime = StartTime;
    view.block = block;
    view.Title = @"取消时间选择";
    view.EndTime = EndTime;
    view.CZblock = CZBlock;
    [view setupview];
    return view;
}

- (void)setupview{
    [[DTKTool getCurrentVC].view addSubview:self];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    self.viewH = kwt(400);
    UIView * makeView = [UIView new];
    self.makeView = makeView;
    makeView.backgroundColor = UIColor.whiteColor;
    makeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,  self.viewH);
    [self addSubview:makeView];
    [DTKTool BFYJ:kwt(15) andView:makeView andCorner:UIRectCornerTopLeft|UIRectCornerTopRight andSize: CGRectMake(0, 0 ,SCREEN_WIDTH,  self.viewH)];
    
    //
    //    makeView.userInteractionEnabled = YES;
    //    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noclick)]];
    //    self.userInteractionEnabled = YES;
    //    [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)]];
    //    makeView.userInteractionEnabled = YES;
    //    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noclick)]];
    
    
    UIView * topview = [UIView new];
    [makeView addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(kwt(52));
    }];
    
    UILabel * toplab = [DTKTool labelWithText:self.Title andFont:kCFont(18) andTextColor:KcolorHex(@"#242729")];
    [topview addSubview:toplab];
    [toplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(20));
        make.centerY.offset(0);
    }];
    
    UIButton * btn = [UIButton buttonWithType:0];
    [btn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    btn.addTarget(self,@selector(dismiss));
    [topview addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(20));
        make.centerY.equalTo(toplab);
    }];
    
    UILabel * temp = [DTKTool labelWithText:@"至" andFont:kFont(18) andTextColor:KcolorHex(@"#242729")];
    [makeView addSubview:temp];
    [temp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(75));
    }];
    MJWeakSelf
    UILabel * StartTimeLab = [DTKTool labelWithText:(self.StartTime.length > 0)?self.StartTime:@"开始时间" andFont:(self.StartTime.length > 0)?kCFont(18):kFont(18) andTextColor:(self.StartTime.length > 0)?KcolorHex(@"#0967FF"):KcolorHex(@"#8B9093")];
    self.StartTimeLab = StartTimeLab;
    StartTimeLab.addClickBlock(^{
        [weakSelf startClick];
    });
    StartTimeLab.textAlignment = NSTextAlignmentCenter;
    [makeView addSubview:StartTimeLab];
    [StartTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(20));
        make.right.equalTo(temp.mas_left).offset(kwt(-20));
        make.centerY.equalTo(temp).offset(kwt(-2));
    }];
    
    UIView * StartTimeview = [UIView new];
    StartTimeview.backgroundColor = KcolorHex(@"#0967FF");
    self.StartTimeview = StartTimeview;
    [makeView addSubview:StartTimeview];
    [StartTimeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.right.equalTo(temp.mas_left).offset(kwt(-15));
        make.centerY.equalTo(temp).offset(kwt(23));
        make.height.offset(1);
    }];
    
    UILabel * EndTimeLab = [DTKTool labelWithText:(self.EndTime.length > 0)?self.EndTime:@"结束时间" andFont:(self.EndTime.length > 0)?kCFont(18):kFont(18) andTextColor:(self.EndTime.length > 0)?KcolorHex(@"#0967FF"):KcolorHex(@"#8B9093")];
    self.EndTimeLab = EndTimeLab;
    EndTimeLab.addClickBlock(^{
        [weakSelf EndClick];
    });
    EndTimeLab.textAlignment = NSTextAlignmentCenter;
    [makeView addSubview:EndTimeLab];
    [EndTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-20));
        make.left.equalTo(temp.mas_right).offset(kwt(20));
        make.centerY.equalTo(temp).offset(kwt(-2));
    }];
    
    
    UIView * EndTimeview = [UIView new];
    EndTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    self.EndTimeview = EndTimeview;
    [makeView addSubview:EndTimeview];
    [EndTimeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.left.equalTo(temp.mas_right).offset(kwt(15));
        make.centerY.equalTo(temp).offset(kwt(23));
        make.height.offset(1);
    }];
    
    UIView * buttonview = [UIView new];
    [makeView addSubview:buttonview];
    [buttonview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(63) + KSafeAreaBottomHeight);
    }];
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = KcolorHex(@"#F0F2F4");
    if(self.isCZ){
        [qxbtn setTitle:@"重置" forState:UIControlStateNormal];
    } else {
        [qxbtn setTitle:@"清空" forState:UIControlStateNormal];
    }
    [qxbtn setTitleColor:KcolorHex(@"#5A6066") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qxbtn];
    [qxbtn addTarget:self action:@selector(leftBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(44));
        make.width.offset(kwt(160));
        make.left.offset(kwt(20));
        make.top.offset(kwt(10));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(160), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")];
    [qrbtn setTitle:@"确定" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qrbtn];
    [qrbtn addTarget:self action:@selector(rightbtnclick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(44));
        make.width.offset(kwt(160));
        make.right.offset(kwt(-20));
        make.top.offset(kwt(10));
    }];
    
    UIView * pickview = [UIView new];
    [makeView addSubview:pickview];
    [pickview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(128));
        make.bottom.equalTo(buttonview.mas_top);
    }];
    
    BRDatePickerView * pickerView = [[BRDatePickerView alloc] initWithPickerMode:BRDatePickerModeYMD];
    BRPickerStyle * style = [BRPickerStyle new];
    style.hiddenMaskView = YES;
//    style.pickerColor = UIColor.clearColor;
//    style.dateUnitTextColor = KcolorHex(@"#000000");
//    style.dateUnitTextFont = kFont(17);
    pickerView.pickerStyle = style;
    self.pickerView = pickerView;
//    //    pickerView.numberOfComponents = 3;
//    pickerView.resultModelArrayBlock = ^(NSArray<BRResultModel *> * _Nullable resultModelArr) {
//        if(weakSelf.block){
//            weakSelf.block(weakSelf.taskType,resultModelArr.firstObject.value.integerValue ,resultModelArr.lastObject.value.integerValue);
//            [weakSelf dismiss];
//        }
//    };
    [pickerView addPickerToView:pickview];
    
    [self startClick];
    [self show];
}

- (void)startClick{
    self.pickerView.minDate = nil;
    if(self.EndTime.length > 0){
        self.pickerView.maxDate = [NSDate br_dateFromString:self.EndTime dateFormat:@"yyyy-MM-dd"];
        self.EndTimeLab.textColor = KcolorHex(@"#242729");
    } else {
        self.pickerView.maxDate = nil;
        self.EndTimeLab.textColor =  KcolorHex(@"#8B9093");
    }
    if(self.StartTime.length > 0){
        self.pickerView.selectDate =  [NSDate br_dateFromString:self.StartTime dateFormat:@"yyyy-MM-dd"];
        self.StartTimeLab.textColor = KcolorHex(@"#0967FF");
    } else {
        self.StartTimeLab.textColor = KcolorHex(@"#8B9093");
    }
    [self.pickerView reloadData];
    MJWeakSelf
    self.pickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
        weakSelf.StartTimeLab.text = selectValue;
        weakSelf.StartTime = selectValue;
    };
    
    self.StartTimeview.backgroundColor = KcolorHex(@"#0967FF");
    self.EndTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    
}
- (void)EndClick{
    self.pickerView.maxDate = nil;
    self.StartTimeLab.textColor = KcolorHex(@"#242729");

    if(self.StartTime.length > 0){
        self.pickerView.minDate = [NSDate br_dateFromString:self.StartTime dateFormat:@"yyyy-MM-dd"];
    } else {
        self.pickerView.minDate = nil;
        self.StartTimeLab.textColor =  KcolorHex(@"#8B9093");
    }
    if(self.EndTime.length > 0){
        self.pickerView.selectDate =  [NSDate br_dateFromString:self.EndTime dateFormat:@"yyyy-MM-dd"];
        self.EndTimeLab.textColor = KcolorHex(@"#0967FF");
    } else {
        self.EndTimeLab.textColor = KcolorHex(@"#8B9093");
    }
    [self.pickerView reloadData];
    MJWeakSelf
    self.pickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.EndTimeLab.textColor = KcolorHex(@"#0967FF");
        weakSelf.EndTimeLab.text = selectValue;
        weakSelf.EndTime = selectValue;
    };
    self.StartTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    self.EndTimeview.backgroundColor = KcolorHex(@"#0967FF");

    
    
}
- (void)leftBtnclick{
//    [self dismiss];
//    self.StartTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
//    self.EndTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
//    self.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
//    self.StartTimeLab.text =  self.StartTime;
//    self.EndTimeLab.textColor =  KcolorHex(@"#8B9093");
//    self.EndTimeLab.text = self.EndTime;
//    [self startClick];
    self.CZblock();
    [self dismiss];
}

- (void)rightbtnclick{
    if(self.StartTime.length < 1){
//        [self showWarning:@"请选择开始时间"];
        self.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
        self.StartTimeLab.text =  [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
        self.StartTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
        return;
    }
    if(self.EndTime.length < 1){
//        [self showWarning:@"请选择结束时间"];
        self.EndTimeLab.textColor = KcolorHex(@"#0967FF");
        self.EndTimeLab.text = self.StartTime;
        self.EndTime = self.StartTime;
        [self EndClick];
        return;
    }
    self.block(self.StartTime, self.EndTime);
    [self dismiss];
}


- (void)show{
    [[DTKTool getCurrentVC].view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT - self.viewH , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
    }];
}
- (void)noclick{}
- (void)dismiss{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}
@end





@interface DayTimeFrameShowView ()
@property (nonatomic ,strong) NSString * StartTime;
@property (nonatomic ,strong) NSString * EndTime;
@property (nonatomic ,strong) NSString * Title;
@property (nonatomic ,strong) UILabel * StartTimeLab;
@property (nonatomic ,strong) UIView * StartTimeview;
@property (nonatomic ,strong) UILabel * EndTimeLab;
@property (nonatomic ,strong) UIView * EndTimeview;


@property (nonatomic ,strong) void(^block)(NSString * StartTime,NSString * EndTime);
@property (nonatomic ,strong) void(^CZblock)(void);

@property (nonatomic ,strong) UIView * makeView;
@property (nonatomic ,assign) CGFloat viewH;
@property (nonatomic ,assign) BOOL isCZ;
@property (nonatomic ,strong) BRDatePickerView * pickerView;
@end

@implementation DayTimeFrameShowView

+ (instancetype)CZshowviewWithTitle:(NSString *)Title andStartTime:(NSString *)StartTime andEndTime:(NSString *)EndTime andRightBlock:(void(^)(NSString * StartTime,NSString * EndTime))block andCZBlock:(void(^)(void))CZBlock{
    DayTimeFrameShowView * view = [DayTimeFrameShowView new];
    view.isCZ = YES;
    view.StartTime = StartTime;
    view.block = block;
    view.Title = Title;
    view.EndTime = EndTime;
    view.CZblock = CZBlock;
    [view setupview];
    return view;
}

- (void)setupview{
    [[DTKTool getCurrentVC].view addSubview:self];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    self.viewH = kwt(400);
    UIView * makeView = [UIView new];
    self.makeView = makeView;
    makeView.backgroundColor = UIColor.whiteColor;
    makeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,  self.viewH);
    [self addSubview:makeView];
    [DTKTool BFYJ:kwt(15) andView:makeView andCorner:UIRectCornerTopLeft|UIRectCornerTopRight andSize: CGRectMake(0, 0 ,SCREEN_WIDTH,  self.viewH)];
    
    //
    //    makeView.userInteractionEnabled = YES;
    //    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noclick)]];
    //    self.userInteractionEnabled = YES;
    //    [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)]];
    //    makeView.userInteractionEnabled = YES;
    //    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(noclick)]];
    
    
    UIView * topview = [UIView new];
    [makeView addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(kwt(52));
    }];
    
    UILabel * toplab = [DTKTool labelWithText:self.Title andFont:kCFont(18) andTextColor:KcolorHex(@"#242729")];
    [topview addSubview:toplab];
    [toplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(20));
        make.centerY.offset(0);
    }];
    
    UIButton * btn = [UIButton buttonWithType:0];
    [btn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    btn.addTarget(self,@selector(dismiss));
    [topview addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(20));
        make.centerY.equalTo(toplab);
    }];
    
    UILabel * temp = [DTKTool labelWithText:@"至" andFont:kFont(18) andTextColor:KcolorHex(@"#242729")];
    [makeView addSubview:temp];
    [temp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(75));
    }];
    MJWeakSelf
    UILabel * StartTimeLab = [DTKTool labelWithText:(self.StartTime.length > 0)?self.StartTime:@"开始时间" andFont:(self.StartTime.length > 0)?kCFont(18):kFont(18) andTextColor:(self.StartTime.length > 0)?KcolorHex(@"#0967FF"):KcolorHex(@"#8B9093")];
    self.StartTimeLab = StartTimeLab;
    StartTimeLab.addClickBlock(^{
        [weakSelf startClick];
    });
    StartTimeLab.textAlignment = NSTextAlignmentCenter;
    [makeView addSubview:StartTimeLab];
    [StartTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(20));
        make.right.equalTo(temp.mas_left).offset(kwt(-20));
        make.centerY.equalTo(temp).offset(kwt(-2));
    }];
    
    UIView * StartTimeview = [UIView new];
    StartTimeview.backgroundColor = KcolorHex(@"#0967FF");
    self.StartTimeview = StartTimeview;
    [makeView addSubview:StartTimeview];
    [StartTimeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.right.equalTo(temp.mas_left).offset(kwt(-15));
        make.centerY.equalTo(temp).offset(kwt(23));
        make.height.offset(1);
    }];
    
    UILabel * EndTimeLab = [DTKTool labelWithText:(self.EndTime.length > 0)?self.EndTime:@"结束时间" andFont:(self.EndTime.length > 0)?kCFont(18):kFont(18) andTextColor:(self.EndTime.length > 0)?KcolorHex(@"#0967FF"):KcolorHex(@"#8B9093")];
    self.EndTimeLab = EndTimeLab;
    EndTimeLab.addClickBlock(^{
        [weakSelf EndClick];
    });
    EndTimeLab.textAlignment = NSTextAlignmentCenter;
    [makeView addSubview:EndTimeLab];
    [EndTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-20));
        make.left.equalTo(temp.mas_right).offset(kwt(20));
        make.centerY.equalTo(temp).offset(kwt(-2));
    }];
    
    
    UIView * EndTimeview = [UIView new];
    EndTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    self.EndTimeview = EndTimeview;
    [makeView addSubview:EndTimeview];
    [EndTimeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.left.equalTo(temp.mas_right).offset(kwt(15));
        make.centerY.equalTo(temp).offset(kwt(23));
        make.height.offset(1);
    }];
    
    UIView * buttonview = [UIView new];
    [makeView addSubview:buttonview];
    [buttonview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(63) + KSafeAreaBottomHeight);
    }];
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = KcolorHex(@"#F0F2F4");
    if(self.isCZ){
        [qxbtn setTitle:@"重置" forState:UIControlStateNormal];
    } else {
        [qxbtn setTitle:@"清空" forState:UIControlStateNormal];
    }
    [qxbtn setTitleColor:KcolorHex(@"#5A6066") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qxbtn];
    [qxbtn addTarget:self action:@selector(leftBtnclick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(44));
        make.width.offset(kwt(160));
        make.left.offset(kwt(20));
        make.top.offset(kwt(10));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(160), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")];
    [qrbtn setTitle:@"确定" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qrbtn];
    [qrbtn addTarget:self action:@selector(rightbtnclick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(44));
        make.width.offset(kwt(160));
        make.right.offset(kwt(-20));
        make.top.offset(kwt(10));
    }];
    
    UIView * pickview = [UIView new];
    [makeView addSubview:pickview];
    [pickview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(128));
        make.bottom.equalTo(buttonview.mas_top);
    }];
    
    BRDatePickerView * pickerView = [[BRDatePickerView alloc] initWithPickerMode:BRDatePickerModeHM];
    BRPickerStyle * style = [BRPickerStyle new];
    style.hiddenMaskView = YES;
//    style.pickerColor = UIColor.clearColor;
//    style.dateUnitTextColor = KcolorHex(@"#000000");
//    style.dateUnitTextFont = kFont(17);
    pickerView.pickerStyle = style;
    self.pickerView = pickerView;
//    //    pickerView.numberOfComponents = 3;
//    pickerView.resultModelArrayBlock = ^(NSArray<BRResultModel *> * _Nullable resultModelArr) {
//        if(weakSelf.block){
//            weakSelf.block(weakSelf.taskType,resultModelArr.firstObject.value.integerValue ,resultModelArr.lastObject.value.integerValue);
//            [weakSelf dismiss];
//        }
//    };
    [pickerView addPickerToView:pickview];
    
    [self startClick];
    [self show];
}

- (void)startClick{
    self.pickerView.minDate = [NSDate br_setYear:2000 month:1 day:1 hour:0 minute:0];
    if(self.EndTime.length > 0){
        self.pickerView.maxDate = [NSDate br_dateFromString:self.EndTime dateFormat:@"HH:mm"];
        self.EndTimeLab.textColor = KcolorHex(@"#242729");
    } else {
        self.pickerView.maxDate = [NSDate br_setYear:2000 month:1 day:1 hour:23 minute:59];
        self.EndTimeLab.textColor =  KcolorHex(@"#8B9093");
    }
    if(self.StartTime.length > 0){
        self.pickerView.selectDate =  [NSDate br_dateFromString:self.StartTime dateFormat:@"HH:mm"];
        self.StartTimeLab.textColor = KcolorHex(@"#0967FF");
    } else {
        self.StartTimeLab.textColor = KcolorHex(@"#8B9093");
    }
    NSLog(@"时间范围是%@-%@",self.pickerView.minDate,self.pickerView.maxDate);
    [self.pickerView reloadData];
    MJWeakSelf
    self.pickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
        weakSelf.StartTimeLab.text = selectValue;
        weakSelf.StartTime = selectValue;
    };
    
    self.StartTimeview.backgroundColor = KcolorHex(@"#0967FF");
    self.EndTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    
}
- (void)EndClick{
    self.pickerView.maxDate = [NSDate br_setYear:2000 month:1 day:1 hour:23 minute:59];
    self.StartTimeLab.textColor = KcolorHex(@"#242729");

    if(self.StartTime.length > 0){
        self.pickerView.minDate = [NSDate br_dateFromString:self.StartTime dateFormat:@"HH:mm"];
    } else {
        self.pickerView.minDate = [NSDate br_setYear:2000 month:1 day:1 hour:0 minute:0];
        self.StartTimeLab.textColor =  KcolorHex(@"#8B9093");
    }
    if(self.EndTime.length > 0){
        self.pickerView.selectDate =  [NSDate br_dateFromString:self.EndTime dateFormat:@"HH:mm"];
        self.EndTimeLab.textColor = KcolorHex(@"#0967FF");
    } else {
        self.EndTimeLab.textColor = KcolorHex(@"#8B9093");
    }
    NSLog(@"时间范围是%@-%@",self.pickerView.minDate,self.pickerView.maxDate);

    [self.pickerView reloadData];
    MJWeakSelf
    self.pickerView.changeBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.EndTimeLab.textColor = KcolorHex(@"#0967FF");
        weakSelf.EndTimeLab.text = selectValue;
        weakSelf.EndTime = selectValue;
    };
    self.StartTimeview.backgroundColor = KcolorHex(@"#D8D8D8");
    self.EndTimeview.backgroundColor = KcolorHex(@"#0967FF");

    
    
}
- (void)leftBtnclick{
//    [self dismiss];
//    self.StartTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
//    self.EndTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"];
//    self.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
//    self.StartTimeLab.text =  self.StartTime;
//    self.EndTimeLab.textColor =  KcolorHex(@"#8B9093");
//    self.EndTimeLab.text = self.EndTime;
//    [self startClick];
    self.CZblock();
    [self dismiss];
}

- (void)rightbtnclick{
    if(self.StartTime.length < 1){
//        [self showWarning:@"请选择开始时间"];
        self.StartTimeLab.textColor =  KcolorHex(@"#0967FF");
        self.StartTimeLab.text =  [NSDate br_stringFromDate:[NSDate new] dateFormat:@"HH:mm"];
        self.StartTime = [NSDate br_stringFromDate:[NSDate new] dateFormat:@"HH:mm"];
        return;
    }
    if(self.EndTime.length < 1){
//        [self showWarning:@"请选择结束时间"];
        self.EndTimeLab.textColor = KcolorHex(@"#0967FF");
        self.EndTimeLab.text = self.StartTime;
        self.EndTime = self.StartTime;
        [self EndClick];
        return;
    }
    self.block(self.StartTime, self.EndTime);
    [self dismiss];
}


- (void)show{
    [[DTKTool getCurrentVC].view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT - self.viewH , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
    }];
}
- (void)noclick{}
- (void)dismiss{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}
@end
